<a href="#/layui/busiMemList" class="layui-btn layui-btn-xs layui-btn-primary" style="margin: 20px 0 0 100px;">
  <i class="layui-icon">&#xe65c;</i>
</a>

<form class="layui-form" action="">

<div class="layui-container">
	<div class="layui-row">
    <div class="layui-col-md5">
      <h2 class="title">编辑会员</h2>
     <form action="" class="layui-form">
      	<table class="layui-table" lay-size="lg" lay-skin="nob">
		   <tbody>
		   		<tr>
		   			<td>会员ID：</td>
		   			<td><input type="text" name="memberId" required  class="layui-input memberId"></td>
		   		</tr>
		   		<tr>
		   			<td>会员姓名：</td>
		   			<td><input type="text" name="memberName" required  class="layui-input memberName"></td>
		   		</tr>
		   		<tr>
		   			<td>职业名称：</td>
		   			<td>
		   				<select name="jobsName" lay-verify="required" id="jobsName" class="jobsName" lay-filter="jobsName">
				        <option value="">请选择</option>
				      </select>
		   			</td>
		   		</tr>
		   		<tr>
		   			<td>一级行业：</td>
		   			<td>
		   				<select name="fristJobs" class="fristJobs" lay-verify="required" lay-filter="fristJobs">
				        <option value="">请选择</option>
				      </select>
		   			</td>
		   		</tr>
		   		<tr>
		   			<td>二级行业：</td>
		   			<td>
		   				<select name="secJobs" class="secJobs" id="secJobs" lay-verify="required" lay-filter="secJobs">
				        <option value="">请选择</option>
				      </select>
		   			</td>
		   		</tr>
		   		<tr>
		   			<td>会员手机号：</td>
		   			<td><input type="text" name="memberPhone" required class="layui-input memberPhone"></td>
		   		</tr>
		   </tbody>   
		      
		      	
	      </table>
	      
	      <div class="save-warp">
	      	
	      	<button class="addLevBtn layui-btn saveBtn" name="saveBtn" type="button">保存</button>
	      </div>
	      
		
	      
      	</form>
      
      
      
      <style scoped>
      	.title{
      		margin-left: 30px;
      		margin-top: 30px;
      	}
      	.save-warp{
      		width: 100%;
      		text-align: center;
      		margin-top: 20px;
      	}
      	.save-warp button{
      		display: inline-block;
      		width: 160px;
      	}
      	
      	
      </style>
      
      
      
      
    </div>
  </div>
</div>

</form>

<script type="text/javascript" src="../../api/DBHelper.js"></script>
<script type="text/javascript">
	//重新渲染表单
function renderForm(){
  layui.use('form', function(){
   var form = layui.form;//高版本建议把括号去掉，有的低版本，需要加()
   form.render();
  });
}
let fristJobs = document.querySelector(".fristJobs");
let secJobs = document.querySelector(".secJobs");
let jobsName = document.querySelector(".jobsName");
let saveBtn = document.querySelector(".saveBtn");
let memberId = document.querySelector(".memberId");
let memberName = document.querySelector(".memberName");
let memberPhone = document.querySelector(".memberPhone");
let seFrist="";
let seSec="";
let seSecText="";
let job="";



layui.use(['jquery', 'mockjs', 'table', 'sidebar', 'form','route'], function () {
		var $ = layui.jquery,
      layer = layui.layer,
      table = layui.table,
      sidebar = layui.sidebar,
      route = layui.route,
      params = route.params(),
      form = layui.form;
      console.log(params.id);
//    职位名称
			DBHelper.Get("Admin_Xn_Member?id="+params.id, function(data){
				console.log(data)
				memberId.value = data.Guid;
				memberName.value = data.RealName;
				memberPhone.value = data.Mobile;
			}, function(data){
				console.log(data)
			})

      $.ajax({//异步请求返回给后台
		    	  url:'http://xnsmb.xnsoft.net.cn/api/GetXn_Position',
		    	  type:'get',
		    	  data:{},
		    	  dataType:'json',
		    	  beforeSend: function(request) {
		            
		            request.setRequestHeader("Authorization", 'bearer ' + localStorage.getItem("token"));
		        },
		    	  success:function(data){
		    		  //这里获取到数据执行显示
//		    		  console.log(data)
		    		  data.forEach((el,index)=>{
		    		  	let op = document.createElement('option');
		    		  	op.value = el.Name;
		    		  	op.innerText = el.Name;
		    		  	jobsName.appendChild(op)
		    		  })
		    		  renderForm();
		    	  }
		    	  
		      });
		      
//		      一二级行业
		$.ajax({//异步请求返回给后台
		    	  url:'http://xnsmb.xnsoft.net.cn/api/GetXn_Trade',
		    	  type:'get',
		    	  data:{FatherId:'00'},
		    	  dataType:'json',
		    	  beforeSend: function(request) {
		            
		            request.setRequestHeader("Authorization", 'bearer ' + localStorage.getItem("token"));
		        },
		    	  success:function(data){
		    		  //这里获取到数据执行显示
//		    		  console.log(data)
		    		  data.forEach((el,index)=>{
		    		  	let op = document.createElement('option');
		    		  	op.value = el.Code;
		    		  	op.innerText = el.Name;
		    		  	fristJobs.appendChild(op)
		    		  	
		    		  })
		    		  renderForm();
		    	  }
		    	  
		      });
		      
		form.on('select(fristJobs)', function(data){
			seFrist = data;
//			console.log("seFrist",seFrist)
//		  console.log(data.value);
		  $.ajax({//异步请求返回给后台
		    	  url:'http://xnsmb.xnsoft.net.cn/api/GetXn_Trade',
		    	  type:'get',
		    	  data:{FatherId:data.value},
		    	  dataType:'json',
		    	  beforeSend: function(request) {
		            
		            request.setRequestHeader("Authorization", 'bearer ' + localStorage.getItem("token"));
		        },
		    	  success:function(data){
							$("#secJobs").empty();
							let p = document.createElement('option');
							p.value = "";
							p.innerText = "请选择";
							secJobs.appendChild(p)
		    		  data.forEach((el,index)=>{
		    		  	let op = document.createElement('option');
		    		  	op.value = el.Id;
		    		  	op.innerText = el.Name;
//		    		  	op.id = el.Id;
		    		  	secJobs.appendChild(op)
		    		  })
		    		  renderForm();
		    		  
		    	  }
		    	  
		      });
		});   
		
		form.on('select(secJobs)', function(data){
			seSec = data;
//			console.log("seSec",seSec)
//			console.log("seSec",data.elem[data.elem.selectedIndex].id)
			seSecText = data.elem[data.elem.selectedIndex].text;
//			console.log("seSecText",seSecText)
			
		})
		form.on('select(jobsName)', function(data){
			job = data;
//			console.log("job",job)
//			console.log("data.value",data.value);
		})
		
		saveBtn.addEventListener("click",function(){
			console.log(params)
			DBHelper.Put("Admin_Xn_Member?id="+params.id,{
				Guid:'00000000-0000-0000-0000-000000000000',
		  	MemLoginId:memberId.value,	
		  	Pwd:'',
		  	NickName:'',
		  	RealName:memberName.value,
		  	MaxPhoto:'',
		  	MinPhoto:'',
		  	MultiPhoto:'',
		  	Mobile:memberPhone.value,
		  	Email:'',
		  	RankScore:'',
		  	RankGuid:'00000000-0000-0000-0000-000000000000',
		  	WxId:'',
		  	Company:'',
		  	CompanyArea:'',
		  	CompanyAreaCode:'',
		  	CompanyAddress:'',
		  	WWW:'',
		  	Area:'',
		  	AreaCode:'',
		  	Address:'',
		  	Position:job.value,
		  	Trade:seSecText,
		  	TradeId:seSec.value,
		  	Brief:'',
		  	SharedResource:'',
		  	DemandResources:'',
		  	BrowseCount:'',
		  	CollectCount:'',
		  	TransmitCount:'',
		  	LikeCount:'',
		  	CreateUser:'',
		  	CreateTime:'',
		  	ModifyUser:'',
		  	ModifyTime:'',
		  	WxUnionId:'0'
			},function(data){
				console.log(data)
			},
			function(data){
				console.log(data)
			})
			
			
		})
		
})
</script>